package o;

import android.app.Application;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.util.LruCache;
import com.huawei.skinner.attrentry.SkinAttrFactory;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

public class flr {
    private static final Object ˋ = new Object();
    private static volatile flr ˏ;
    private boolean ʻ = false;
    private boolean ʼ = true;
    private int ʽ = 1;
    private flo ˊ;
    private ExecutorService ˊॱ = Executors.newSingleThreadExecutor(ˏ("HwSkinner SkinManager", false));
    private LruCache<String, WeakReference<flo>> ˎ = new LruCache(5);
    private flk ˏॱ;
    private Handler ͺ = new Handler(Looper.getMainLooper());
    private List<fln> ॱ;
    private AsyncTask ॱˊ;
    private boolean ॱॱ = false;
    private Context ᐝ;

    private flr(Context context) {
        Context applicationContext = context.getApplicationContext();
        if (applicationContext == null) {
            this.ᐝ = context;
        } else {
            this.ᐝ = ((Application) applicationContext).getBaseContext();
        }
        SkinAttrFactory.init(context);
    }

    public static flr ˋ(Context context) {
        return ˎ(context);
    }

    @Deprecated
    public static flr ˎ() {
        if (ˏ != null) {
            return ˏ;
        }
        throw new dg("HwSkinner::Init::Invoke init(context) first!");
    }

    public static flr ˎ(Context context) {
        if (ˏ == null) {
            synchronized (ˋ) {
                if (ˏ == null) {
                    ˏ = new flr(context);
                }
            }
        }
        return ˏ;
    }

    public boolean ˋ() {
        return (this.ʼ || this.ˊ == null) ? false : true;
    }

    public boolean ॱ() {
        return this.ʻ;
    }

    public void ˏ(final String str, flk o_flk) {
        if (this.ॱॱ && fms.ˎ().ॱ().ॱ().ˎ().equals(str)) {
            this.ʻ = true;
        } else {
            this.ʻ = false;
        }
        if (this.ॱˊ == null) {
            if (this.ʻ) {
                this.ʽ = 2;
            }
            this.ˏॱ = o_flk;
            this.ॱˊ = new AsyncTask<String, Void, flo>(this) {
                final /* synthetic */ flr ॱ;

                protected /* synthetic */ Object doInBackground(Object[] objArr) {
                    return ॱ((String[]) objArr);
                }

                protected /* synthetic */ void onPostExecute(Object obj) {
                    ॱ((flo) obj);
                }

                protected void onPreExecute() {
                    if (this.ॱ.ˏॱ != null) {
                        this.ॱ.ˏॱ.ˏ();
                    }
                }

                protected flo ॱ(String... strArr) {
                    flo o_flo = null;
                    try {
                        File ˎ = this.ॱ.ˏ(str);
                        if (ˎ != null) {
                            o_flo = this.ॱ.ˊ(ˎ);
                        }
                    } catch (Exception e) {
                        fmq.ˎ("SkinManager.load failed " + e.getMessage());
                    }
                    return o_flo;
                }

                protected void ॱ(flo o_flo) {
                    if (o_flo != null) {
                        fkv.ˊ(str);
                        this.ॱ.ʼ = false;
                        if (o_flo != this.ॱ.ˊ) {
                            this.ॱ.ˊ = o_flo;
                            this.ॱ.ᐝ();
                            return;
                        }
                        this.ॱ.ॱˊ = null;
                        this.ॱ.ʽ = 1;
                        fmq.ˊ("SkinManager.load： skin had loaded!");
                        return;
                    }
                    this.ॱ.ʼ = true;
                    this.ॱ.ʻ = false;
                    this.ॱ.ʽ = 1;
                    if (this.ॱ.ˏॱ != null) {
                        this.ॱ.ˏॱ.ˊ();
                    }
                    this.ॱ.ॱˊ = null;
                }
            }.executeOnExecutor(this.ˊॱ, new String[]{str});
        }
    }

    private ThreadFactory ˏ(final String str, final boolean z) {
        return new ThreadFactory(this) {
            final /* synthetic */ flr ˊ;

            public Thread newThread(Runnable runnable) {
                Thread thread = new Thread(runnable, str);
                thread.setDaemon(z);
                return thread;
            }
        };
    }

    private File ˏ(String str) {
        File file = new File(str);
        if (file.exists() && str.endsWith(".apk")) {
            return file;
        }
        return null;
    }

    public flo ˊ(File file) {
        if (file == null || !file.exists()) {
            fmq.ˊ("SkinManager.loadPlugin apk is null or apk no exists!");
            return null;
        }
        flo ˋ = ˋ(file.getName());
        if (ˋ != null) {
            return ˋ;
        }
        ˋ = flo.ॱ(this, this.ᐝ, file);
        this.ˎ.put(file.getName(), new WeakReference(ˋ));
        return ˋ;
    }

    public flo ˋ(String str) {
        WeakReference weakReference = (WeakReference) this.ˎ.get(str);
        return weakReference == null ? null : (flo) weakReference.get();
    }

    public Context ˏ() {
        return this.ᐝ;
    }

    public flo ˊ() {
        return this.ˊ;
    }

    public void ˎ(flo o_flo) {
        if (this.ˊ != o_flo) {
            this.ˊ = o_flo;
            ᐝ();
        }
    }

    public void ॱ(fln o_fln) {
        if (this.ॱ == null) {
            this.ॱ = new ArrayList();
        }
        if (!this.ॱ.contains(o_fln)) {
            this.ॱ.add(o_fln);
        }
    }

    public void ˎ(fln o_fln) {
        if (this.ॱ != null && this.ॱ.contains(o_fln)) {
            this.ॱ.remove(o_fln);
        }
    }

    public void ᐝ() {
        if (this.ॱ != null && this.ॱ.size() > 0) {
            for (fln ˑ : this.ॱ) {
                ˑ.ˑ();
            }
        }
        c.ˊ().ˏ(new Runnable(this) {
            final /* synthetic */ flr ˊ;

            {
                this.ˊ = r1;
            }

            public void run() {
                this.ˊ.ͺ.post(new Runnable(this) {
                    final /* synthetic */ AnonymousClass4 ॱ;

                    {
                        this.ॱ = r1;
                    }

                    public void run() {
                        if (this.ॱ.ˊ.ʻ) {
                            this.ॱ.ˊ.ʽ();
                        }
                        if (this.ॱ.ˊ.ˏॱ != null) {
                            this.ॱ.ˊ.ˏॱ.ॱ();
                        }
                        this.ॱ.ˊ.ʽ = 1;
                        this.ॱ.ˊ.ॱˊ = null;
                    }
                });
                c.ˊ().ˏ(null);
            }
        });
    }

    private void ʽ() {
        if (this.ॱ != null && this.ॱ.size() > 0) {
            for (fln ـ : this.ॱ) {
                ـ.ـ();
            }
        }
        this.ʽ = 1;
    }

    public flr ˋ(List<fku> list) {
        fpf.ˎ(list);
        return this;
    }

    public flr ˎ(String str, Class cls, Class cls2) {
        SkinAttrFactory.registerSkinAttr(str, cls, cls2);
        return this;
    }

    public boolean ʻ() {
        return this.ॱॱ;
    }
}
